package com.hyuk.hyukfgw.service.token.bean;

import lombok.Data;

import java.io.Serializable;

@Data
public class TokenInfo implements Serializable {
    
    private static final long serialVersionUID = -5591839515528389265L;
    
    /**
     * 过期时间
     */
    private Long expireTimeMillis;
    
    /**
     * 用户id
     */
    private String userId;
    
    /**
     * 用户姓名
     */
    private String userName;
    
    /**
     * 判断 token 是否过期
     *
     * @return
     */
    public boolean isExpired() {
        return expireTimeMillis == null || System.currentTimeMillis() > expireTimeMillis;
    }
    
    /**
     * 判断 token 是否存活
     *
     * @return
     */
    public boolean isAlive() {
        return !isExpired();
    }
    
    private static class EmptyHolder {
        private static final TokenInfo INSTANCE = new TokenInfo();
    }
    
    public static TokenInfo getEmptyInstance() {
        return EmptyHolder.INSTANCE;
    }
}
